﻿using System.Xml.Linq;
using IDeal.Models;
using IDeal.Services;

namespace IDeal.Serialization
{
    internal class ErrorResponseXmlReader : XmlMessageReader<ErrorResponse>
    {
        public ErrorResponseXmlReader(IIDealServices iDealServices) : base(iDealServices)
        {
        }

        protected override void ParseRootElement(ErrorResponse instance, XElement rootElement)
        {
            var errorElement = rootElement.Element(Ns + "Error");

            instance.Code = errorElement.Element(Ns + "errorCode").Value;
            instance.Message = errorElement.Element(Ns + "errorMessage").Value;
            instance.Detail = errorElement.Element(Ns + "errorDetail").Value;
            instance.ConsumerMessage = errorElement.Element(Ns + "consumerMessage").Value;
        }
    }
}
